//
//  ServicePlatFormTableViewCell.swift
//  kxf
//
//  Created by Mac on 2024/3/24.
//

import Foundation
import UIKit

class ServicePlatFormTableViewCell: UITableViewCell {
    
    var peizhiBlock:(()->())?
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .clear
        self.selectionStyle = .none
        initUI()
    }
    lazy var whiteView : UIView = {
        let vi = UIView()
        vi.layer.cornerRadius = kFitWidth(10)
        vi.clipsToBounds = true
        vi.backgroundColor = .white
        vi.isUserInteractionEnabled = true
        
        return vi
    }()
    lazy var payTypeImgView : UIImageView = {
        let img = UIImageView()
        
        return img
    }()
    lazy var nameLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 16, weight: .medium)
        lab.adjustsFontSizeToFitWidth = true
        
        return lab
    }()
    lazy var timeLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 14, weight: .regular)
        lab.adjustsFontSizeToFitWidth = true
        
        return lab
    }()
    lazy var rebateLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 14, weight: .regular)
        lab.adjustsFontSizeToFitWidth = true
        
        return lab
    }()
    lazy var payTypeLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK999
        lab.font = .systemFont(ofSize: 14, weight: .regular)
        lab.adjustsFontSizeToFitWidth = true
        
        return lab
    }()
    lazy var moneyLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 16, weight: .bold)
        lab.adjustsFontSizeToFitWidth = true
        
        return lab
    }()
    lazy var lineView : UIView = {
        let vi = UIView()
        vi.backgroundColor = .COLOR_LIGHT_GREY
        
        return vi
    }()
}

extension ServicePlatFormTableViewCell{
    func updateUI(dict:NSDictionary) {
//        if dict["channel"]as? String ?? "" == "微信支付"{
//            payTypeImgView.setImgLocal(imgName: "pay_type_wechat_icon")
//        }else if dict["channel"]as? String ?? "" == "支付宝"{
//            payTypeImgView.setImgLocal(imgName: "pay_type_alipay_icon")
//        }else if dict["channel"]as? String ?? "" == "首信易钱包"{
//            payTypeImgView.setImgLocal(imgName: "pay_type_sxy_icon")
//        }else{
//            payTypeImgView.setImgLocal(imgName: "pay_type_unipay_icon")
//        }
        
        if dict.stringValueForKey(key: "payType") == "2"{
            payTypeImgView.setImgLocal(imgName: "pay_type_wechat_icon")
        }else if dict.stringValueForKey(key: "payType") == "3"{
            payTypeImgView.setImgLocal(imgName: "pay_type_alipay_icon")
        }else if dict.stringValueForKey(key: "payType") == "7"{//京东
            payTypeImgView.setImgLocal(imgName: "pay_type_jd_icon")
        }else if dict.stringValueForKey(key: "payType") == "1" || dict.stringValueForKey(key: "payType") == "6"{
            payTypeImgView.setImgLocal(imgName: "pay_type_sxy_icon")
        }else{
            payTypeImgView.setImgLocal(imgName: "pay_type_unipay_icon")
        }
        
        nameLabel.text = dict["user_name"]as? String ?? ""
        
        timeLabel.text = "时间：\(dict["create_time"]as? String ?? "")"
        rebateLabel.text = "收益：\(dict["amount"]as? Double ?? 0.00)"
        moneyLabel.text = "¥\(dict["trade_amount"]as? Double ?? 0.00)"
        
        if dict["sec_service"]as? String ?? "" == "1"{
            payTypeLabel.text = "结算方式:合并到账"
        }else{
            payTypeLabel.text = "结算方式:实时到账"
        }
    }
}
extension ServicePlatFormTableViewCell{
    func initUI() {
        contentView.addSubview(whiteView)
        whiteView.addSubview(payTypeImgView)
        whiteView.addSubview(nameLabel)
        whiteView.addSubview(timeLabel)
        whiteView.addSubview(rebateLabel)
        whiteView.addSubview(payTypeLabel)
        whiteView.addSubview(moneyLabel)
        whiteView.addSubview(lineView)
        
        setConstrait()
    }
    func setConstrait() {
        whiteView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.width.equalTo(kFitWidth(343))
            make.height.equalTo(kFitWidth(131))
            make.top.equalToSuperview()
        }
        payTypeImgView.snp.makeConstraints { make in
            make.left.top.equalTo(kFitWidth(12))
            make.width.height.equalTo(kFitWidth(22))
        }
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(38))
            make.centerY.lessThanOrEqualTo(payTypeImgView)
            make.right.equalTo(kFitWidth(-20))
        }
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(12))
            make.top.equalTo(kFitWidth(48))
        }
        rebateLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(12))
            make.top.equalTo(kFitWidth(75))
            make.height.equalTo(kFitWidth(17))
        }
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(12))
            make.top.equalTo(kFitWidth(75))
            make.height.equalTo(kFitWidth(17))
        }
        lineView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.bottom.equalTo(kFitWidth(-32))
            make.height.equalTo(kFitWidth(0.4))
        }
        payTypeLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(12))
            make.bottom.right.equalToSuperview()
            make.height.equalTo(kFitWidth(32))
        }
        moneyLabel.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-12))
            make.top.equalTo(kFitWidth(32))
        }
    }
}
